<?php
class ModemsController extends AppController {

	var $name = 'Modems';

	function index() {
		$this->Modem->recursive = 0;
		$this->set('modems', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid modem', true));
			$this->redirect($this->referer());
		}
		$this->set('modem', $this->Modem->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Modem->create();
			if ($this->Modem->save($this->data)) {
				$this->Session->setFlash(__('The modem has been saved', true));
				$this->redirect(array('controller' => 'audits', 'action' => 'view/'.$this->data['Modem']['audit_id']));
			} else {
				$this->Session->setFlash(__('The modem could not be saved. Please, try again.', true));
			}
		}
		$audits = $this->Modem->Audit->find('list');
		$this->set(compact('audits'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid modem', true));
			$this->redirect($this->referer());
		}
		if (!empty($this->data)) {
			if ($this->Modem->save($this->data)) {
				$this->Session->setFlash(__('The modem has been saved', true));
				$this->redirect(array('controller' => 'audits', 'action' => 'view/'.$this->data['Modem']['audit_id']));
			} else {
				$this->Session->setFlash(__('The modem could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Modem->read(null, $id);
		}
		$audits = $this->Modem->Audit->find('list');
		$this->set(compact('audits'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for modem', true));
			$this->redirect($this->referer());
		}
		if ($this->Modem->delete($id)) {
			$this->Session->setFlash(__('Modem deleted', true));
			$this->redirect($this->referer());
		}
		$this->Session->setFlash(__('Modem was not deleted', true));
		$this->redirect($this->referer());
	}
}
?>